package top.lshaci.learning.alibaba.cloud.seata.order.service.impl;

import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.lshaci.learning.alibaba.cloud.seata.order.feign.StorageFeign;
import top.lshaci.learning.alibaba.cloud.seata.order.service.BusinessService;
import top.lshaci.learning.alibaba.cloud.seata.order.service.OrderService;

/**
 * BusinessServiceImpl
 *
 * @author lshaci
 * @since 1.0.0
 */
@Service
@AllArgsConstructor
public class BusinessServiceImpl implements BusinessService {

    private final StorageFeign storageFeign;

    private final OrderService orderService;

    /**
     * 采购
     */
    @Override
    @GlobalTransactional
    @Transactional(rollbackFor = Exception.class)
    public void purchase(String userId, String commodityCode, int orderCount) {
        storageFeign.deduct(commodityCode, orderCount);
        orderService.create(userId, commodityCode, orderCount);
    }
}
